/*
 * @Description: 
 * @Version: 2.0
 * @Autor: ftt
 * @Date: 2022-03-29 11:51:24
 * @LastEditors: TT
 * @LastEditTime: 2022-12-02 14:54:18
 */

import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/foundation.dart';
import 'package:hzy_normal_widget/hzy_config.dart';
//全部打印
import 'dart:developer';

import 'package:ttcomment/ttcomment.dart';

class HzyNormalUtils {
  static configSizeMaxW(double maxw) {
    return maxw > HzyConfig.maxw ? HzyConfig.maxw : maxw;
  }

  static configEndRefresh({
    int? type,
    PageState? state,
    EasyRefreshController? refreshController,
  }) {
    IndicatorResult result = IndicatorResult.success;
    if (state == PageState.noMoreDataState) {
      result = IndicatorResult.noMore;
    }
    if (state == PageState.errorState ||
        state == PageState.erroronlyTotal ||
        state == PageState.errorshowRelesh) {
      result = IndicatorResult.fail;
    } else if (state == PageState.noMoreDataState) {
      result = IndicatorResult.noMore;
    }
    if (refreshController != null) {
      if (type == 1) {
        refreshController.finishRefresh(result);
      } else if (type == 2) {
        refreshController.finishLoad(result);
      }
    }
    return state;
  }
}

debugprint(Object? object) {
  if (kDebugMode) {
    // print("================ STAR ================");
    //json表示接口返回的数据
    if (kIsWeb) {
      print(object.toString());
    } else {
      log(object.toString());
    }

    // print("================ END ================ ");
  }
}

/// 信息太长,分段打印
p(String msg) {
  //因为String的length是字符数量不是字节数量所以为了防止中文字符过多，
  //  把4*1024的MAX字节打印长度改为1000字符数
  int maxStrLength = 1000;
  //大于1000时
  while (msg.length > maxStrLength) {
    if (kDebugMode) {
      print(msg.substring(0, maxStrLength));
    }
    msg = msg.substring(maxStrLength);
  }
  if (kDebugMode) {
    //剩余部分
    print(msg);
  }
}
